/*
 * @Descripttion:
 * @version: 1.0.0
 * @Author: htang
 * @Date: 2024-03-02 15:03:50
 * @LastEditors: htang
 * @LastEditTime: 2024-03-03 12:18:54
 */
import { defHttp } from '/@/utils/http/axios';
import { createVNode } from 'vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Modal, message } from 'ant-design-vue';

export const API = {
  // 门禁列表分页
  page: '/access/page',
  // 门禁列表
  list: '/access/list',
  // 门禁删除
  delete: '/access/delete',
  // 门禁详情
  info: '/access/info',
  // 新增门禁信息
  add: '/access/add',
  // 修改门禁信息
  modify: '/access/modify',
  // 操作历史查询
  log: '/access/log/page',
  // 控制
  control: '/access/control',
  // 7天门禁操作日志
  count: '/access/log/count'
};

/**
 * 门禁列表分页
 */
export const accessPageApi = async (params) => {
  return await defHttp.get({ url: API.page, params });
};

/**
 * 门禁操作日志
 */
export const accessLogApi = async (params) => {
  return await defHttp.get({ url: API.log, params });
};

/**
 * 门禁操作日志
 */
export const accessLogCountApi = async () => {
  return await defHttp.get({ url: API.count });
};

/**
 * 门禁详细信息
 */
export const accessInfoApi = async (params) => {
  return await defHttp.get({ url: API.info, params });
};

/**
 * 门禁控制
 */
export const accessControlApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.control, data }).then((res) => {
          resolve(true);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
};